using System;
using System.Globalization;
using Xamarin.Forms;

namespace DailyPoetryX.Converters {
    public class LastSyncToStringConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter,
            CultureInfo culture) {
            if (!(value is DateTime time)) return null;
            var timeSpan = DateTime.Now - time;

            if (timeSpan.Days == 0) {
                return "今天刚刚成功地同步过。";
            } else {
                return $"距离上一次成功同步已有{timeSpan.Days}天。";
            }
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture) {
            throw new NotImplementedException();
        }
    }
}